--[[ 
Title: Suicide Kings
Author: Brom
Version: 0.1
]]

local function RandomCharacter()
    
    -- 0-9, A-Z, a-z = 10 + 26 + 16
    local i = math.random(0,61)
    
    -- strip offset and ascii jump
    if ( i >= 36 ) then
        -- a:z
        i = ( i - 36 ) + 97
    elseif ( i >= 10 ) then
        -- A:Z
        i = ( i - 10 ) + 65
    else
        -- 0:9
        i = ( i + 48 )
    end
    
    return string.char( i )

end

function SuicideKings:UID( reserved )
    
    -- uid length
    -- unique values = 62^4 = 14776336
    local length = 4
    
    -- generate a random string
    local s = RandomCharacter()
    for i = 1, length-1 do
        local c = RandomCharacter()
        s = s .. c
    end
    
    -- if taken, try again
    while ( reserved[s] ~= nil ) do
        s = SuicideKings:UID( reserved )
    end
    
    return s
    
end